import { defineStore } from "pinia";
import { loginResponse } from "@/types/apiTypes";
import { formatRouter } from "@/router/helper.ts";

export default defineStore("userStore", {
  persist: {
    storage: sessionStorage,
  },

  state: () => {
    return {
      userData: {} as loginResponse,
    };
  },

  getters: {
    userMenus(state) {
      return formatRouter(state?.userData?.sysMenus || []);
    },
  },

  actions: {
    async setUserData(userData: loginResponse) {
      this.userData = userData;
    },
  },
});
